﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NCT.Framework;
using VISS.API.Users;

namespace VISS.Web.BackEnd.Modules.User {

    public partial class UserMessagePage : System.Web.UI.Page {

        protected string ListTitle { get; set; }

        protected void Page_Load(object sender, EventArgs e) {
            int pageNum = ConvertUtils.ToInt(Request.QueryString["page"], 1);
            string userKey = ConvertUtils.ToString(Request.QueryString["key"], "");
            ListTitle = "Danh Sách Tin Nhắn";
            long totalRecord = 0;
            string queryString = string.Empty;
            if (userKey != "") {
                int tempTotal = 0;
                idMessageList.MessageList = StructureMapFactory.GetInstance<IUserMessageAdmin>().GetBySentUserKeyWithPaging(userKey, pageNum, AppSettings.RecordPerPageOfMessage, out tempTotal);
                totalRecord = tempTotal;
                queryString = "key=" + userKey + "&";
                idMessageList.DisplayLink = false;                
            }
            else {
                idMessageList.MessageList = StructureMapFactory.GetInstance<IUserMessageAdmin>().GetAllWithPaging(pageNum, AppSettings.RecordPerPageOfMessage, out totalRecord);
                idMessageList.DisplayLink = true;
                
            }

            idPaging.TotalRecord = totalRecord;
            idPaging.PageSize = AppSettings.RecordPerPageOfMessage;
            idPaging.CurrentPage = pageNum;
            idPaging.TargetPage = "/users/tin_nhan";
            idPaging.QueryString = queryString;
        }
    }
}
